<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Sistema gerenciador escolar</title>
        <link type="text/css" rel="stylesheet" href="dot-luv/skin.css"/>
    </h:head>
    <h:body>
        <p:layout fullPage="true">
            <p:layoutUnit position="left" width="200" header="Atividades" resizable="true" closable="true" collapsible="true">
                <h:form prependId="false">
                    <p:commandLink value="Novo Professor" actionListener="#{professorManagedBeans.prepararAdicionarProfessor}" update="infosProfessor" oncomplete="dialogGerProfessor.show()"/>
                </h:form>
            </p:layoutUnit>
            <p:layoutUnit position="center">
                <h1>Gerenciador Escolar</h1>
                <br/>
                <h:form prependId="false">
                    <p:dataTable id="tabela" var="professor" value="#{professorManagedBeans.listarProfessors}">
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Nome"/>
                            </f:facet>
                            <h:outputText value="#{professor.nome}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Telefone"/>
                            </f:facet>
                            <h:outputText value="#{professor.telefone}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="CPF"/>
                            </f:facet>
                            <h:outputText value="#{professor.cpf}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="RG"/>
                            </f:facet>
                            <h:outputText value="#{professor.rg}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Situação"/>
                            </f:facet>
                            <h:outputText value="#{professor.situacao}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Disciplina"/>
                            </f:facet>
                            <h:outputText value="#{professor.disciplina.nome}"/>
                        </p:column>
                        
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Alterar"/>
                            </f:facet>
                            <p:commandButton actionListener="#{professorManagedBeans.prepararAlterarProfessor}" value="Alterar" update="infosProfessor" oncomplete="dialogGerProfessor.show()"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Excluir"/>
                            </f:facet>
                            <h:commandLink action="#{professorManagedBeans.excluirProfessor}" value="Excluir"/>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </p:layoutUnit>
        </p:layout>

        <p:dialog header="Sistema de gerenciamento escolar" widgetVar="dialogGerProfessor"  resizable="false" modal="true" showEffect="slide" width="500">
            <h:form prependId="false">
                <h:panelGrid id="infosProfessor" columns="2" style="margin-bottom:10px">

                    <h:outputLabel for="nome" value="Nome:" />
                    <h:inputText id="nome" value="#{professorManagedBeans.professor.nome}"/>

                    <h:outputLabel for="telefone" value="Telefone:" />
                    <p:inputMask id="telefone" size="15" value="#{professorManagedBeans.professor.telefone}" mask="(99)9999-9999" requiredMessage="Campo obrigatório não preenchido"/>
                                        
                    <h:outputLabel for="cpf" value="CPF:" />
                    <p:inputMask id="cpf" size="15" value="#{professorManagedBeans.professor.cpf}" mask="999.999.999-99" requiredMessage="Campo obrigatório não preenchido"/>
                   
                    <h:outputLabel for="rg" value="RG:" />
                    <p:inputMask id="rg" size="15" value="#{professorManagedBeans.professor.rg}" mask="999999999" requiredMessage="Campo obrigatório não preenchido"/>
                    
					<h:outputLabel for="disciplina" value="Disciplina:" />
                    <h:selectOneMenu id="disciplina" value="#{professorManagedBeans.disciplinaCadastro.id}" label="Disciplina" required="true">
                        <f:selectItem itemValue="--Selecione uma disciplina--"/>
                         <f:selectItems value="#{professorManagedBeans.disciplinas}" 
                         var = "dis" itemLabel="#{dis.nome}" itemValue="#{dis.id}" />
                    </h:selectOneMenu>
                
                    <h:outputLabel for="situacao" value="Situação:" />
                    <h:selectOneMenu id="situacao" value="#{professorManagedBeans.professor.situacao}">
                        <f:selectItem itemLabel="Ativo" itemValue="1"/>
                        <f:selectItem itemLabel="Inativo" itemValue="2"/>
                    </h:selectOneMenu>

                    <p:commandButton update="tabela" oncomplete="dialogGerProfessor.hide();" actionListener="#{professorManagedBeans.adicionarProfessor}" value="Inserir Professor"/>
                    <p:commandButton update="tabela" oncomplete="dialogGerProfessor.hide();" actionListener="#{professorManagedBeans.alterarProfessor}" value="Alterar Professor"/>

                </h:panelGrid>
            </h:form>
        </p:dialog>

    </h:body>
</html>